const axios = require('axios');
const qs = require('qs'); // 表单上传数据使用

// const FormData = require('form-data'); // 文件上传数据使用
const URL = 'http://www.rssso.com/api/CmsPost/Publish';

module.exports = (data, url = URL) => {
  return new Promise((resolve, reject) => {
    const { catid, title } = data;
    if (!catid) {
      return reject('请求类别id不能为空');
    }
    if (!title) {
      return reject('请求标题不能为空');
    }
    axios({
      method: 'post',
      url,
      headers: { 'content-type': 'application/x-www-form-urlencoded' }, // 设置请求头为表单上传
      data: qs.stringify(data)
    })
      .then(res => {
        res.data.Success ? resolve(true) : resolve(false);
      })
      .catch(err => {
        reject(err.toString());
      });
  });
};
